package com.book.bridge.abst;

import com.book.bridge.function.RegisterLoginByDefault;
import com.book.bridge.function.RegisterLoginFuncInterface;
import com.book.pojo.UserInfo;

import javax.servlet.http.HttpServletRequest;

public abstract class AbstractRegisterLoginComponent {

    // 面向接口编程
    protected RegisterLoginFuncInterface funcInterface;
    // 构造注入

    public AbstractRegisterLoginComponent(RegisterLoginFuncInterface funcInterface) {
        validate(funcInterface);
        this.funcInterface = funcInterface;
    }

    protected final void validate(RegisterLoginFuncInterface funcInterface){
        if (!(funcInterface instanceof RegisterLoginByDefault)) {
            throw new UnsupportedOperationException("Unknown register/login function type !");
        }
    };

    protected abstract String login(String account, String password);

    protected abstract  String register(UserInfo userInfo);

    protected abstract boolean checkUserExists(String username);

    protected abstract String login3rd(HttpServletRequest request);
}
